package com.alone.wchat.common.net.url;

import com.google.gson.*;

import java.lang.reflect.Type;

public class ShortUrlRespDeserializer implements JsonDeserializer<ShortUrlResp> {

	@Override
	public ShortUrlResp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
			throws JsonParseException {

		final JsonObject root = json.getAsJsonObject();

		final int status = root.get("status").getAsInt();
		final String info = root.get("info").getAsString();

		JsonObject data = root.get("data").getAsJsonObject();
		String shortUrl = data.get("short_url").getAsString();

		ShortUrlResp resp = new ShortUrlResp();
		resp.setStatus(status);
		resp.setInfo(info);
		resp.setShortUrl(shortUrl);

		return resp;
	}

}
